#tag Class
Protected Class App
Inherits Application
	#tag Event
		Sub Open()
		  dim reg as New ExtRegClass
		  do
		  loop until reg.RegisterAll
		  
		  mPrefs=MakePreferences()
		  mPrefs.Read()
		  
		  lang=MakeLanguage()
		  lang.Read()
		  
		  do
		  loop until ConnectDb
		  
		  //check if user is admin
		  
		  dim n as string
		  n=SystemInformationMBS.Username
		  
		  IsAdmin=true
		  
		  'if mydb<>nil then
		  '
		  'dim rs as recordset
		  'rs=mydb.SQLSelect("SELECT isadmin FROM "+app.mprefs.getstring("dbschema")+".users WHERE username='"+n+"'")
		  '
		  'if mydb.error then MsgBox mydb.errormessage
		  '
		  'if rs<>nil then
		  'IsAdmin=(rs.field("isadmin").integervalue=1)
		  'end
		  '
		  'end
		End Sub
	#tag EndEvent


	#tag MenuHandler
		Function FileImportTracks() As Boolean Handles FileImportTracks.Action
			AlbumImportWin.show
			
			Return True
			
		End Function
	#tag EndMenuHandler

	#tag MenuHandler
		Function FileNewTrack() As Boolean Handles FileNewTrack.Action
			RMMetaWin.show
			RMMetaWin.MySong=New MusicDataObject
			RMMetaWin.IsUpdated=false
			RMMetaWin.SetView
			RMMetaWin.SaveBackToImportWin=false
			
			Return True
			
		End Function
	#tag EndMenuHandler

	#tag MenuHandler
		Function FileOptions() As Boolean Handles FileOptions.Action
			SetupWin.show
			
			Return True
			
		End Function
	#tag EndMenuHandler

	#tag MenuHandler
		Function FileSearchTracks() As Boolean Handles FileSearchTracks.Action
			SearchWin.show
			
			Return True
			
		End Function
	#tag EndMenuHandler

	#tag MenuHandler
		Function FileTrackInfo() As Boolean Handles FileTrackInfo.Action
			RMMetaWin.show
			
			if Mainwin.TheSong<>nil then
			RMMetaWin.MySong=Mainwin.TheSong
			RMMetaWin.IsUpdated=true
			else
			RMMetaWin.MySong=New MusicDataObject
			RMMetaWin.IsUpdated=false
			end
			
			RMMetaWin.SetView
			RMMetaWin.SaveBackToImportWin=false
			
			Return True
			
		End Function
	#tag EndMenuHandler

	#tag MenuHandler
		Function HelpAbout() As Boolean Handles HelpAbout.Action
			AboutWin.show
			
			Return True
			
		End Function
	#tag EndMenuHandler

	#tag MenuHandler
		Function HelpCheckUpdates() As Boolean Handles HelpCheckUpdates.Action
			dim f as folderitem
			dim m as string
			f=GetFolderItem("updater.exe")
			if f<>nil and f.exists then
			
			f.launch
			MainWin.updSocket.Path=SpecialFolder.SharedApplicationData.absolutepath
			MainWin.updSocket.Connect
			
			m=ConvertEncoding("0000"+CHR(31)+"PING?",Encodings.ASCII)
			
			MainWin.updSocket.Write(m)
			
			end
			
			Return True
			
		End Function
	#tag EndMenuHandler


	#tag Method, Flags = &h0
		Function MakeLanguage() As LangContainer
		  dim theLang as LangContainer
		  
		  //Create Language Object
		  
		  theLang=new LangContainer(CurrentLang+".LANG")
		  
		  return(theLang)
		End Function
	#tag EndMethod

	#tag Method, Flags = &h0
		Function MakePreferences() As PrefContainer
		  dim thePrefs as PrefContainer
		  
		  //Create Preferences Object
		  #if TargetWin32 then
		    thePrefs=new PrefContainer("player.ini")
		  #else
		    thePrefs=new PrefContainer("player.prefs")
		  #endif
		  
		  return(thePrefs)
		End Function
	#tag EndMethod


	#tag ComputedProperty, Flags = &h0
		#tag Getter
			Get
			  return app.mprefs.getstring("langid")
			End Get
		#tag EndGetter
		CurrentLang As String
	#tag EndComputedProperty

	#tag Property, Flags = &h0
		IsAdmin As Boolean
	#tag EndProperty

	#tag Property, Flags = &h0
		lang As LangContainer
	#tag EndProperty

	#tag Property, Flags = &h0
		mPrefs As PrefContainer
	#tag EndProperty


	#tag Constant, Name = kEditClear, Type = String, Dynamic = False, Default = \"&Delete", Scope = Public
		#Tag Instance, Platform = Windows, Language = Default, Definition  = \"&Delete"
		#Tag Instance, Platform = Linux, Language = Default, Definition  = \"&Delete"
	#tag EndConstant

	#tag Constant, Name = kFileQuit, Type = String, Dynamic = False, Default = \"&Quit", Scope = Public
		#Tag Instance, Platform = Windows, Language = Default, Definition  = \"E&xit"
	#tag EndConstant

	#tag Constant, Name = kFileQuitShortcut, Type = String, Dynamic = False, Default = \"", Scope = Public
		#Tag Instance, Platform = Mac OS, Language = Default, Definition  = \"Cmd+Q"
		#Tag Instance, Platform = Linux, Language = Default, Definition  = \"Ctrl+Q"
	#tag EndConstant


	#tag ViewBehavior
		#tag ViewProperty
			Name="CurrentLang"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
		#tag EndViewProperty
		#tag ViewProperty
			Name="IsAdmin"
			Group="Behavior"
			Type="Boolean"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
